<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="css/base.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery-form.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=request.getContextPath() %>/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
	src="<%=request.getContextPath() %>/js/ueditor/ueditor.all.min.js"> </script>


<script type="text/javascript">
	$(function(){
		 var ue = UE.getEditor('container');
		//异步提交缩略图 
		$('#head').change(function(){
			$('#up_image').ajaxSubmit({
  				url:"industry_upImage.action",   	//发送请求的url地址
  				dataType:"text",			//返回
  				success:function(data){ 	//当请求之后调用。传入返回后的数据，以及包含成功代码的字符串。
  					$('#soul').attr('src',"news_image/"+data);   //拿被选中的src属性，并设置
  					$('#v_head').val(data);	//隐藏框 拿到返回的data值  				
  				}
			})
		});
			
		//准备数据，准备保存
			$('.submit').click(function(){
				var flag = true;
				var obj = {};
				$.each($('.control'),function(){
					var thiz = $(this);
					if (thiz.attr('data-text') == 'text') {
						if (!thiz.val()) {
							thiz.focus();
							thiz.next().html("输入值不能为空");
							flag = false;
							return false;
						}
					} 
				obj["newsPO."+thiz.attr('name')] = thiz.val();//给属性赋值
				thiz.next().html("");
			});
				//给上传图片名字属性赋值
				var Name = $('#soul').attr('src');
				var imageName = Name.substring(11);
				obj["newsPO."+$('#soul').attr('name')] = imageName;  
				
				
				if (flag) {
					//修改学生信息
					var id = <%=request.getParameter("id") %> 
					if (id != null) {
						$.ajax({
							url:"industry_update.action?id="+id,		
							type:"post",
							dataType:"json",
							data:obj,
							success:function(data){
								if ('EC001' == data.code){
								 	alert("修改信息成功");
									window.location.href="industry_show.action";	
								} else {
									alert("修改信息失败，请重试!");
								}
							}
						})
					}else{
						//保存学生数据
						$.ajax({
							url:"industry_saveInfo.action",
							type:"post", //请求方式
							dataType:"json", //回执数据的数据类型
							data:obj, //向后台传送的数据
							success:function(data){
								if ('EC001' == data.code){
								 	alert("添加信息成功");
									window.location.href="industry_show.action";	
								} else {
									alert("添加信息失败，请重试!");
								}
							}
						}) 
					}
					
				}
				 
				 
			});
	});
</script>


</head>

<body>
	<div class="main_right_top">
		您现在所在位置 > <span>添加优秀学员</span>
	</div>
	<div class="main_right_body">
		<div class="body_content">
			<div class="add_xm_all">
				<h1 class="add_xm_top">基本信息</h1>
				<!--add_xm_top-->
				<div class="add_xm_form">
					<ul>
						<li><label>新闻标题：</label> <input type="text" class="control"
							data-text='text' name="title" value="${newsPO.title }" /> <span
							class="error_text"></span></li>
						<li>
							<%-- <label>新闻简介：</label>
                            <input type="text" class="control" data-text='text' name="intro" value="${newsPO.intro }"/>	
                            <span class="error_text"></span>	 --%>
							<div id="container" style="width:500px;margin:0px auto  "></div>
						</li>
						<li><label>发表时间：</label> <input type="text" class="control"
							data-text='text' name="date" value="${newsPO.date }" /> <span
							class="error_text"></span></li>

						<li><label>上传照片：</label> <input type="hidden" name="head"
							id="v_head" />
							<form action="industry_upImage.action" method="post"
								enctype="multipart/form-data" id="up_image">
								<input type="file" id="head" name="image" />
							</form> <span> <img src="" id="soul" name="img_url">
						</span></li>

					</ul>
					<div class="regist_btn">
						<input type="submit" value="提交" class="submit" /> <a
							class="return_btn">返回</a>
					</div>
				</div>
				<!--add_xm_form-->
			</div>
			<!--add_xm_all-->
		</div>
	</div>
	<!--main_right_body-->

</body>
</html>